package pl.com.qapps.unity;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Properties;

/**
 * @author Jakub Dykowski
 * 
 */
class TestScriptExtractor {

	private static FileAttribute<?> ATTRS = PosixFilePermissions
			.asFileAttribute(PosixFilePermissions.fromString("rwxrwxrwx"));
	private static Properties props = new Properties();

	public static void main(String[] args) throws IOException {
		props.load(Unity.class.getResourceAsStream("unity.properties"));

		Path script = Paths.get("/tmp", "pl.com.qapps.unity.unity_service");

		if (Files.notExists(script, LinkOption.NOFOLLOW_LINKS)) {
			System.out.println("creating script: " + script);
			Files.copy(Unity.class.getResourceAsStream("unity.py"), script,
					StandardCopyOption.REPLACE_EXISTING);
		}

		System.out.printf("script exists: %s",
				Files.exists(script, LinkOption.NOFOLLOW_LINKS));
	}
}
